package com.project.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.EventBean;
import com.project.service.EventService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * 事件
 */
@Controller
@RequestMapping("event")
public class EventController {


    @Resource
    private EventService eventService;


    /**
     * 显示所有事件信息
     * @param pageNO
     * @param pageSize
     * @return
     */
    @RequestMapping("findAllEvent")
    @ResponseBody
    public IPage<EventBean> findAllEvent(
            @RequestParam(value = "pageNO", defaultValue = "1") int pageNO,
            @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return eventService.findAllEvent(pageNO, pageSize);
    }


    //添加
    @RequestMapping("addEvent")
    @ResponseBody
    public String addEvent(EventBean eventBean) {
        eventService.addEvent(eventBean);
        return "添加成功";
    }


    /**
     * id查询
     * @param eventId
     * @return
     */
    @RequestMapping("findId")
    @ResponseBody
    public EventBean findId(int eventId) {
        return eventService.findId(eventId);
    }


    //专家会商
    @RequestMapping("updateConsult")
    @ResponseBody
    public String updateConsult(int eventId) {
        eventService.updateConsult(eventId);
        return "修改成功";
    }


    /**
     * id修改灾情防治
     * @param eventId
     * @param eventStage
     * @param eventPrecept
     * @return
     */
    @RequestMapping("updateEvent")
    @ResponseBody
    public String updateEvent(int eventId, String eventStage, String eventPrecept) {
        eventService.updateEvent(eventId, eventStage, eventPrecept);
        return "修改成功";
    }


    /**
     * 名称阶段途径起始事件模糊查询
     * @param eventName
     * @param eventStage
     * @param eventFind
     * @param startTime
     * @param endTime
     * @return
     */
    @RequestMapping("findName")
    @ResponseBody
    public List<EventBean> findName(String eventName, String eventStage,
                                    String eventFind, LocalDate startTime,
                                    LocalDate endTime) {
        return eventService.findName(eventName, eventStage, eventFind, startTime, endTime);
    }
}
